<?php
namespace app\components\printMachine;

use app\components\printMachine\feie\FeieProvider;
use yii\base\UserException;

class PrintFactory {

    private static $type = [
        '1'=>FeieProvider::class,
        '2'=>FeieProvider::class,
    ];

    /**
     * 实例集合
     * @var array
     */
    private static $_instance = [];

    /**
     * 获取打印机驱动
     * @param $type
     * @return mixed
     * @throws UserException
     */
    public static function getInstance($type) : ProviderInterface {
        if(!array_key_exists($type,self::$type)){
            throw new UserException(\Yii::t("app","驱动类型不支持"));
        }
        if(array_key_exists(self::$type[$type],self::$_instance)){
            return self::$_instance[self::$type[$type]];
        }
        self::$_instance[self::$type[$type]] = new self::$type[$type]($type);
        return self::$_instance[self::$type[$type]];
    }
}